﻿<%@ Page Title="" Language="C#" MasterPageFile="~/admin/admin.master" AutoEventWireup="true" CodeFile="Add_Edit.aspx.cs" Inherits="admin_Polls_Add_Edit" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script language="javascript" type="text/javascript">
    function showRowIndexs() {
        var i = 0;
        $("#tableChoices tr td.tdLabel").each(function () {
            i++;
            $(this).html("Lựa chọn " + i);
        });
    }

    function addFormField() {
        var ctrlID = $("#<%= hidRowIndex.ClientID %>").val();
        $("#tableChoices").append("<tr class='row' id='pRow" + ctrlID + "'><td width='200' class='tdLabel'>Lựa chọn:</td><td><input class='txt250' type='text' name='txtChoice" + ctrlID + "' id='txtChoice" + ctrlID + "'> <a href='#' onClick='removeFormField(\"#pRow" + ctrlID + "\"); return false;'>Xóa</a></td></tr>");
        $("#<%= hidRowIndex.ClientID %>").val(++ctrlID);

        showRowIndexs();
    }

    function removeFormField(id) {
        var cID = $("input:hidden", id).val();
        var data = "{'cID':'" + cID + "'}"; 
        if (cID > 0) 
        {
            $.ajax(
            {
                type: "POST",
                url: "Add_Edit.aspx/DeletePollChoice",
                data: data,
                contentType: "application/json; charset=utf-8",
                dataType: "json"
            });
        }

        $(id).remove();

        showRowIndexs();
    }
    </script>

     <div class="content-box-outer">
        <div class="content-box-right">
       <ul>
    <li  class="content-box-selected"><a href="Add_Edit.aspx" class="new">Thêm</a></li>
    <li><a href="Default.aspx">Bình chọn</a></li>
    
</ul>
        </div>

         <div class="content-box-left">
            <h1>
                Bình chọn</h1>
            
    <div runat="server" id="divMsg" class="mInfo" visible="false">
    </div>
   
        <table width="100%">
            <tr>
                <td width="200">
                    Câu hỏi
                </td>
                <td>
                    <asp:TextBox ID="txtQuestion" runat="server" CssClass="txt350"/>&nbsp;
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Bắt buộc nhập"
                        ControlToValidate="txtQuestion" SetFocusOnError="true" />
                </td>
            </tr>
            <tr>
                <td>
                    Chặn bình chọn nhiều lần: 
                </td>
                <td>
                    <asp:RadioButton Checked="true" GroupName="block" ID="rdoCookie" runat="server" Text="Cookie(safest)" />&nbsp;&nbsp;
                    <asp:RadioButton GroupName="block" ID="rdoIP" runat="server" Text="IP Address" ToolTip="This may cause problems for multiple voters on same network" />&nbsp;&nbsp;
                    <asp:RadioButton GroupName="block" ID="rdoNone" runat="server" Text="Don't block" />
                </td>
            </tr>
            <tr>
                <td>
                    Kích hoạt
                </td>
                <td>
                    <asp:CheckBox runat="server" ID="chkActive" Checked="true" />
                </td>
            </tr>
        </table>
        <div runat="server" id="divChoices">
            <table id='tableChoices' width='100%'>
                <tr id='pRow0'>
                    <td width='200' class='tdLabel'>
                        Lựa chọn 1
                    </td>
                    <td>
                        <input type='text' class='txt250' id='txtChoice0' name='txtChoice0' /> 
                        <a onclick="removeFormField('#pRow0'); return false;" href="#">Xóa</a>
                    </td>
                </tr>
                <tr id='pRow1'>
                    <td width='200' class='tdLabel'>
                        Lựa chọn 2
                    </td>
                    <td>
                        <input type='text' class='txt250' id='txtChoice1' name='txtChoice1' /> 
                        <a onclick="removeFormField('#pRow1'); return false;" href="#">Xóa</a>
                    </td>
                </tr>
            </table>
        </div>
        <asp:HiddenField runat="server" ID="hidRowIndex" Value="2" /> 
        <asp:HiddenField ID="hidPollID" runat="server" />
        
        <input type="button" onclick="addFormField();return false;" value="Thêm Lựa chọn" class="btn" />
        <asp:Button ID="btnSave" runat="server" Text="Lưu" OnClick="btnSave_Click" CssClass="btn primary" />
        
    </div>
    </div>
</asp:Content>

